package ioc

import (
	"gitee.com/chicken-c/go-learn/webook/config"
	"gitee.com/chicken-c/go-learn/webook/internal/events"
	"gitee.com/chicken-c/go-learn/webook/internal/events/article"
	"github.com/IBM/sarama"
)

func InitSaramaClient() sarama.Client {
	cfg := config.Configs.Kafka
	cg := sarama.NewConfig()
	cg.Producer.Return.Successes = true
	client, err := sarama.NewClient(cfg.Addr, cg)
	if err != nil {
		panic(err)
	}
	return client
}

func InitSyncProducer(c sarama.Client) sarama.SyncProducer {
	producer, err := sarama.NewSyncProducerFromClient(c)
	if err != nil {
		panic(err)
	}
	return producer
}

func InitConsumers(c1 *article.InteractiveReadEventConsumer) []events.Consumer {
	return []events.Consumer{c1}
}
